package controller;

import dao.collectDao;
import dao.detailsDao;
import entity.Collect;
import entity.Details;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/caiwu")
public class caiwu {
    @Autowired
    private dao.collectDao collectDao;
    @Autowired
    private dao.detailsDao detailsDao;
    @RequestMapping("/showCollect")
    @ResponseBody
    public Map<String,Object> showCollect(String se,String name,int offset,int limit){
        Map<String,Object> map=new HashMap<>();
        map.put("rows",collectDao.showCollect(name,se,offset,limit));
        map.put("total",collectDao.showCollectTotal(name,se));
        return map;
    }
    @RequestMapping("/showDetails")
    @ResponseBody
    public List<Details> showDetails(String name,String iphoneNum){
        List<Details> list;
        if(name==null){
            Collect collect=collectDao.showCollects(null,null);
            list=detailsDao.showDetails(collect.getBtype(),collect.getIphoneNum());
        }else{
            if(iphoneNum.equals("-")){
                list=detailsDao.showDetails(name,null);
            }else{
                list=detailsDao.showDetails(name,iphoneNum);
            }

        }
        return list;
    }
}
